package com.yuezhi.consumer.config.Publish_Subscribe;

import com.yuezhi.consumer.constant.QueueConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 发布订阅模式
 *  Topic交换机配置
 */
@Configuration
public class RabbitTopicConfig {

    @Bean
    Queue topicOne() {
        return new Queue(QueueConstant.TOPIC_QUEUE_ONE);
    }

    @Bean
    Queue topicTwo() {
        return new Queue(QueueConstant.TOPIC_QUEUE_TWO);
    }

    @Bean
    Queue topicThree() {
        return new Queue(QueueConstant.TOPIC_QUEUE_THREE);
    }

    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange(QueueConstant.TOPIC_EXCHANGE, true, false);
    }

    @Bean
    Binding bindingTopicOne() {
        return BindingBuilder.bind(topicOne()).to(topicExchange()).with("topicOne.#");
    }

    @Bean
    Binding bindingTopicTwo() {
        return BindingBuilder.bind(topicTwo()).to(topicExchange()).with("topicTwo.#");
    }

    @Bean
    Binding bindingTopicThree() {
        return BindingBuilder.bind(topicThree()).to(topicExchange()).with("#.topicThree.#");
    }
}
